Windows x86: Change i128 to return via the vector ABI - #134290
Conversation
|
r? @SparrowLii rustbot has assigned @SparrowLii. Use |
|
This should make us consistent for now, even if Clang isn't yet doing the best thing on MSVC. The third commit's diff shows how the tests change. |
|
@bors try |
Windows x86: Change i128 to return via the vector ABI Clang and GCC both return `i128` in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalar `i128`s using the vector ABI, which makes our `i128` compatible with C. In the future, Clang may change to return `i128` on the stack for its `-msvc` targets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW. Link: rust-lang#134288 (does not fix) try-job: x86_64-msvc try-job: x86_64-msvc-ext1 try-job: x86_64-mingw-1 try-job: x86_64-mingw-2
This comment has been minimized.
This comment has been minimized.
|
💔 Test failed - checks-actions |
|
I validated the codegen on a non-windows machine - it looks like the default filecheck labels get applied based on the host rather than the target? That’s interesting. |
|
Please double check that this doesn't break ABI compat between cg_llvm and cg_clif. And will almost certainly need to be adjusted too. |
That link looks to be for libcalls but those have to already be correct on cranelift, right? We have a hack to use Clang/GCC's return ABI in builtins https://github.com/rust-lang/compiler-builtins/blob/a09218f1c4d23ffbd97d68f0fefb5feed2469dc5/src/macros.rs#L583C9-L583C30. What is the best way to verify Cranelift's ABI? If asm tests can run with both backends then I can add that (also does this get covered in one of the CI jobs?) |
|
__rust_i128_mulo and __rust_u128_mulo do change ABI with this PR: Adjusting the lib_call function directly would also allow getting rid of the if condition at which currently handles the adjustments for non-rust intrinsics. |
I don't think these should change since they return an aggregate type https://github.com/rust-lang/compiler-builtins/blob/a09218f1c4d23ffbd97d68f0fefb5feed2469dc5/src/int/mul.rs#L131, and the change here is only for scalars. Testing with this PR the IR signature for that is: define void @__rust_i128_mulo(ptr dead_on_unwind noalias nocapture noundef writable writeonly sret([32 x i8]) align 16 dereferenceable(32) %_0, ptr noalias nocapture noundef readonly align 16 dereferenceable(16) %a, ptr noalias nocapture noundef readonly align 16 dereferenceable(16) %b) unnamed_addr #0`I can make the adjustments to |
|
huh, why do we rely on certain tuples having a fixed meaning in the C ABI? |
|
Good question :) Maybe those should change to a C-like |
706db2b to
d5bc586
Compare
|
@bors try |
|
@bors ping |
|
😪 I'm awake I'm awake |
|
☀️ Test successful - checks-actions |
|
Finished benchmarking commit (66d6064): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)Results (primary -2.0%, secondary -0.0%)This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 772.501s -> 773.228s (0.09%) |
| //@ [MSVC] compile-flags: --target x86_64-pc-windows-msvc | ||
| //@ [MINGW] compile-flags: --target x86_64-pc-windows-gnu | ||
| //@ [MSVC] filecheck-flags: --check-prefix=WIN | ||
| //@ [MINGW] filecheck-flags: --check-prefix=WIN |
There was a problem hiding this comment.
What is the point of this --check-prefix=WIN? The test can just use the CHECK prefix for annotations that should be checked in all revisions.
There was a problem hiding this comment.
I just did this so we could could add non-windows targets in the same file in the future.
There was a problem hiding this comment.
Ah, great, I did exactly that in #137094. :) However I had to rediscover this as it wasn't clear at all from the test. filecheck-flags: --check-prefix is a super neat trick for making these tests nicer, but I have no idea how anyone is supposed to know about that... it doesn't seem mentioned in the dev guide either?
There was a problem hiding this comment.
Tbh I only thought to try it because I noticed LLVM's tests always set --check-prefix, seems like it's barely used in our suite since bootstrap does it for revisions automatically. I think this hasn't been done much in the past because #![no_core] is pretty awkward to use, but since minicore was added recently this is much better.
Clang and GCC both return
i128in xmm0 on windows-msvc and windows-gnu. Currently, Rust returns the type on the stack. Add a calling convention adjustment so we also return scalari128s using the vector ABI, which makes ouri128compatible with C.In the future, Clang may change to return
i128on the stack for its-msvctargets (more at [1]). If this happens, the change here will need to be adjusted to only affect MinGW.Link: #134288 (does not fix) [1]
try-job: x86_64-msvc
try-job: x86_64-msvc-ext1
try-job: x86_64-mingw-1
try-job: x86_64-mingw-2